package com.bro.person.admin.struct;

import java.io.Serializable;
import java.util.Set;
import java.util.TreeSet;

/**
 * 具体的导航菜单struct
 * @author bruce
 *
 */
public class AdminMenuStruct extends AdminAuthorityStruct implements Comparable<AdminMenuStruct>, Serializable {

	private static final long serialVersionUID = 1L;

	private Integer parentId;
	
	/** 菜单层级(默认为0?)*/
	private Integer level;

	private int sort;

	/** 子菜单 */
	private Set<AdminMenuStruct> menus = null;

	
	public AdminMenuStruct() {
		super();
	}
	
	/**
	 * 构造器
	 * @param id
	 * @param parentId
	 * @param code
	 * @param title
	 * @param link
	 * @param level
	 */
	public AdminMenuStruct(Integer id, Integer parentId, String code, String title, String link, Integer level) {
		super();
		this.id = id;
		this.parentId = parentId;
		this.code = code;
		this.title = title;
		this.link = link;
		this.level = level;
	}
	
	/**
	 * 构造器
	 * @param id
	 * @param parentId
	 * @param code
	 * @param name
	 * @param link
	 * @param level
	 * @param menus
	 */
	public AdminMenuStruct(Integer id, Integer parentId, String code, String name, String link, Integer level,
						   Set<AdminMenuStruct> menus) {
		this(id, parentId, code, name, link, level);
		this.menus = menus;
	}
	
	public Integer getParentId() {
		return parentId;
	}

	public void setParentId(Integer parentId) {
		this.parentId = parentId;
	}

	public Integer getLevel() {
		return level;
	}

	public void setLevel(Integer level) {
		this.level = level;
	}

	public Set<AdminMenuStruct> getMenus() {
		return menus;
	}

	public void setMenus(Set<AdminMenuStruct> menus) {
		this.menus = menus;
	}

	/**
	 * 添加子菜单
	 * 同步操作
	 * @param child
	 */
	public synchronized void addChild(AdminMenuStruct child) {
		if(menus == null){
			menus = new TreeSet<>();
		}
		child.setLevel(this.level==null?1:(this.level+1));
		child.setParentId(this.id);
		this.menus.add(child);
	}
	
	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj instanceof AdminMenuStruct) {
			AdminMenuStruct resourceObj = (AdminMenuStruct) obj;
			if (this.id == resourceObj.id) {
				return true;
			}
		}
		return false;
	}

	@Override
	public String toString() {
		return "AdminMenuStruct [parentId=" + parentId + ", level=" + level + ", menus=" + menus + ", id=" + id
				+ ", code=" + code + ", title=" + title + ", link=" + link + ", navMenu=" + navMenu
				+ ", createTimeMillis=" + createTimeMillis + "]";
	}

	@Override
	public int compareTo(AdminMenuStruct per){
		if(this.sort>per.getSort()){
			return 1;
		}else{
			return -1;
		}
	}

	public int getSort() {
		return sort;
	}

	public void setSort(int sort) {
		this.sort = sort;
	}

	// private String linkTarget;
	// private Short navMenu;
	// private Integer sort;
	// private String remark;

	// private Short status;
	
}
